(function($){
	$.fn.extend({
		validateForm:function(opt){
			var temp = true,
				defaults = {
					msgPosition:'top',
					msgBg:'#f00',
				},
				options = $.extend(defaults,opt),
				$_cur = '';
			//input
			this.find('.validate').each(function(i,v){
				$_cur = $(v);
				var val = $(v).val(),
					v_exp = $(v).data('exp');
					if(v_exp){
						var str = v_exp.indexOf("{"),
						end = v_exp.indexOf("}"),
						getStr = v_exp.substring(str+1,end),
						arry = getStr.split("-"),
						v_type = v_exp.substr(0,1);
					}
				if($(v).is(".require") && !val){
					options.msg = '必填项';
					temp = false;
					return false; 
				}else if(val){
					if(v_type =='c' && !/[\u4e00-\u9fa5]/.test(val)){
						options.msg = '只能是汉字';
						temp = false;
						return false;
					}else if(v_type =='n' && !/^\d+(\.\d+)?$/.test(val)){
						options.msg = '只能是数字';
						temp = false;
						return false;
					}else if(v_type =='e' && !/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(val)){
						options.msg = '邮箱格式不对';
						temp = false;
						return false;
					}else if(v_type =='i' && !/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/.test(val)){
						options.msg = '网址格式不对';
						temp = false;
						return false;
					}else if(arry && (val.length<arry[0] || val.length>arry[1])){
						options.msg ='长度必须是'+getStr+'位';
						temp = false;
						return false;
					}else if(v_type == 'p' && val){
						options.msg ='两次输入密码不一致';
						temp = false;
						return false;
					}
				}
			})
			function getPosition(pos){
				var temp = 1;
				switch(pos){
					case 'top':
						temp = 1;
						break;
					case 'right':
						temp = 2;
						break;
					case 'buttom':
						temp = 3;
						break;
					case 'left':
						temp = 4;
						break;
				};
				return temp;
			}
			if(options.msg){
				layer.tips(options.msg,$_cur, {
					  tips: [getPosition(options.msgPosition),options.msgBg],
					  time: 2000
				});
			}
			return temp;
		}
		
	});
})(jQuery);